export class MessageDTO {
    "sendId": string
    "receivedId": string
    "roomId": string
    "sendDate": any
    "content": any
    /**
     * 0：弹幕
     * 1：rtc信息交互
     */
    "messageType": number

    constructor(sendId: string, receivedId: string, roomId: string, content: any, messageType: number) {
        this.sendId = sendId;
        this.receivedId = receivedId;
        this.roomId = roomId;
        this.content = content;
        this.sendDate = new Date();
        this.messageType = messageType;
    }
}

/**
 * 使用谷歌的stun初始化RTCPeerConnection
 */
const initPeer = () => {
    return new RTCPeerConnection({
        iceServers: [
            {
                urls: "stun:stun.l.google.com:19302"
            }
        ]
    })
}

//流媒体替换
function changeStream(rtcMaps: Map<any, any>, video: any) {
    rtcMaps.forEach(e => {
        const senders = e.getSenders();
        const sender = senders.find((s: any) => s.track.kind === 'video');
        const stream = video.value.srcObject as MediaStream;
        const [videoTracks] = stream.getVideoTracks();
        sender.replaceTrack(videoTracks);
    })
}

export {initPeer, changeStream}

